package com.ningxia.water.controller;

import com.ningxia.water.reuslt.Result;
import com.ningxia.water.reuslt.ResultResponse;
import com.ningxia.water.service.ITsWellInfoService;
import com.ningxia.water.vo.out.MonthConsumedVo;
import com.ningxia.water.vo.out.RankConsumedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author huangzhen
 * @create 2021-05-15 16:41
 */
@RestController
@RequestMapping("/home")
@Api(tags = "业务管理-首页API")
public class HomeController {
    @Autowired
    private ITsWellInfoService wellInfoService;


    /**
     * 统计机井总数，已安装总数，未安装数量，停用数量
     * 用于首页图表、一张图界面
     *
     * @return
     */
    @GetMapping("/getwellStatusCounts")
    @ApiOperation(value = "获取机井数目及其不同状态的数目")
    public Result getwellStatusCounts() {
        return ResultResponse.getSuccessResult(wellInfoService.getWellStatusCount());
    }

    /**
     * 每年全部机井每个月的用水量及全年累计用水量
     * 这里只返回累计用水量
     *
     * @param year
     * @return
     */
    @GetMapping("/totalconsumed")
    @ApiOperation(value = "累计用水量")
    public Result totalConsumed(@RequestParam("year") String year) {
        //获取全部每月消耗用水量
        String startTime = year + "-01";
        String endTime = year + "-12";
        Double totalConsumed = wellInfoService.getTotalConsumed(startTime, endTime);
        return ResultResponse.getSuccessResult(totalConsumed);
    }

    /**
     * 用水量排行 前20
     *
     * @return
     */
    @GetMapping("/rankwaterconsumed")
    @ApiOperation(value = "获取机井用水量排行")
    public Result rankOfWaterConsumed(@RequestParam("year") Integer year) {
        //获取当前时间并格式化
        String startTime = year + "-01";
        String endTime = year + "-12";

        List<RankConsumedVo> lists = wellInfoService.rankOfWaterConsumed(startTime, endTime);
        return ResultResponse.getSuccessResult(lists);
    }

    /**
     * 用水户年度用水量
     *
     * @return
     */
    @GetMapping("/waterconsumed")
    @ApiOperation(value = "用水户年度用水量")
    public Result waterConsumedOfTownAndVillage(@RequestParam("year") Integer year) {
        //获取根据机井ID获取不同乡镇每年用水量
        String startTime = year + "-01";
        String endTime = year + "-12";

        List<RankConsumedVo> lists = wellInfoService.getWaterConsumed(startTime, endTime);

        return ResultResponse.getSuccessResult(lists);
    }

    /**
     * 每年全部机井每个月的用水量
     *
     * @param year
     * @return
     */
    @GetMapping("/monthconsumed")
    @ApiOperation(value = "月用水趋势")
    public Result monthConsumed(@RequestParam("year") String year) {
        //获取全部每月消耗用水量
        String startTime = year + "-01";
        String endTime = year + "-12";
        List<MonthConsumedVo> list = wellInfoService.getMonthConsumed(startTime, endTime);
        return ResultResponse.getSuccessResult(list);
    }

}
